package com.topnav.mc.admin.dao.mapper;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.topnav.mc.admin.bean.OrgUserVo;
import com.topnav.mc.admin.entity.bean.UserBean;
import com.topnav.mc.admin.entity.param.UserParam;
import com.topnav.mc.base.mc.McMapper;
import org.apache.ibatis.annotations.Mapper;
import com.topnav.mc.admin.entity.User;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import java.util.List;
import java.util.Map;

@Mapper
public interface UserMapper extends McMapper<User, UserBean, UserParam> {
	String commSql = " SELECT u.*," +
			" o.code AS orgCode, o.name AS orgName, o.short_name AS orgShortName, o.path AS orgPath, " +
			" o1.code AS loginOrgCode, o1.name AS loginOrgName, o1.short_name AS loginOrgShortName, o1.path AS loginOrgPath," +
			" uo.userOrgs, ur.userRoles " +
			" FROM mc_user u " +
			" LEFT JOIN mc_organization o ON u.org_id = o.id " +
			" LEFT JOIN mc_organization o1 ON u.login_org_id = o1.id " +
			" LEFT JOIN ( " +
			"    SELECT uo.user_id,GROUP_CONCAT(o.short_name) AS userOrgs FROM mc_user_organization uo LEFT JOIN  mc_organization o ON uo.org_id = o.id GROUP BY uo.user_id " +
			" ) uo ON u.id = uo.user_id " +
			" LEFT JOIN ( " +
			"     SELECT ur.user_id,GROUP_CONCAT(r.code) AS userRoles FROM mc_user_role ur LEFT JOIN  mc_role r ON ur.role_id = r.id GROUP BY ur.user_id " +
			" ) ur ON u.id = ur.user_id " +
			" ${ew.customSqlSegment}";

	@Select(commSql)
	UserBean selectInfoOne(@Param(Constants.WRAPPER) Wrapper queryWrapper);

	@Select(commSql)
	List<UserBean> selectInfoList(@Param(Constants.WRAPPER) Wrapper queryWrapper);

	@Select(commSql)
	Page<UserBean> selectInfoPage(Page<UserParam> page, @Param(Constants.WRAPPER) Wrapper queryWrapper);

	/**
	 * 说明：
	 * @类名: UserMapper
	 * <p>
	 *
	 * </p>
	 * @author   kenny
	 * @Date	 2021年11月19日下午6:01:24
	 */

	List<OrgUserVo> searchByOrgPath(Map<String,Object> param);

}
